//
// Created by francklinson on 2021/10/24 AT 10:37.
//
#include <iostream>
#include <array>
#include <string>
#include "Vector.h"

struct Vector3 {
    float x = 0.0f, y = 0.0f, z = 0.0f;
    int *m_MemoryBlock = nullptr;

    Vector3() { m_MemoryBlock = new int[5]; }

    Vector3(float scalar) : x(scalar), y(scalar), z(scalar) {
        m_MemoryBlock = new int[5];
    }

    Vector3(float x, float y, float z) : x(x), y(y), z(z) {
        m_MemoryBlock = new int[5];
    }

    Vector3(const Vector3 &other) = delete;
//            : x(other.x), y(other.y), z(other.z) {
//        std::cout << "Copy" << std::endl;
//    }

    Vector3(Vector3 &&other)
            : x(other.x), y(other.y), z(other.z) {
        m_MemoryBlock = other.m_MemoryBlock;
        other.m_MemoryBlock = nullptr;
        std::cout << "Move" << std::endl;
    }

    // 析构函数
    ~Vector3() {
        std::cout << "Destroy" << std::endl;
        delete[] m_MemoryBlock;
    }

    Vector3 &operator=(const Vector3 &other) = delete;
//            {
//        std::cout << "Copy\n";
//        x = other.x;
//        y = other.y;
//        z = other.z;
//        return *this;
//    }

    Vector3 &operator=(Vector3 &&other) noexcept {
        m_MemoryBlock = other.m_MemoryBlock;
        other.m_MemoryBlock = nullptr;
        std::cout << "Move\n";
        x = other.x;
        y = other.y;
        z = other.z;
        return *this;
    }
};

template<typename T>
void printVector(const Vector<T> &v) {
    for (int i = 0; i < v.Size(); ++i) {
        std::cout << v[i] << std::endl;
    }
    std::cout << "--------------------------\n";
}

template<>
void printVector(const Vector<Vector3> &v) {
    for (int i = 0; i < v.Size(); ++i) {
        std::cout << v[i].x << ", " << v[i].y << ", " << v[i].z << std::endl;
    }
    std::cout << "--------------------------\n";
}

int main() {
//    Vector<std::string> v;
//    v.PushBack("Francklinson");
//    v.PushBack("C++");
//    v.PushBack("Vector");
//    printVector(v);
    {
        Vector<Vector3> v3;
        v3.PushBack(Vector3(1.0f));
        v3.PushBack(Vector3(2, 3, 4));
        v3.PushBack(Vector3());
        printVector(v3);
//        v3.EmplaceBack(1.0f);
//        v3.EmplaceBack(2, 3, 4);
//        v3.EmplaceBack();
//        printVector(v3);
//        v3.EmplaceBack(2, 5, 9);
//        v3.PopBack();
//        v3.EmplaceBack(4, 3, 1);
//        printVector(v3);
//        v3.Clear();
//        printVector(v3);
    }
//    std::cin.get();
    return 0;
}

